import time
from time import localtime,strftime

#时间戳->时间元组->格式化时间

class Time_utils:
    def __init__(self, logger, timetype:str):
        self.logger = logger  #拿到处理日志的工具
        self.begin_time = time.time()
        self.end_time = None
        self.timetype = timetype

        self.logger.info('> {0}: begin_time: {1}'.format(timetype, strftime("%y-%m-%d  %H:%M:%S", localtime(self.begin_time))))


    def compute_time(self):
        end_time = time.time()
        process_time = end_time-self.begin_time
        self.logger.info('> {0}: end_time: {1}'.format(self.timetype, strftime("%y-%m-%d   %H:%M:%S",localtime(end_time))))
        self.logger.info('> {0}: processing_time: {1}'.format(self.timetype, process_time))
        return process_time
        #self.logger.info('> {0}: processing_time: {1}'.format(self.timetype, time.strftime("%H:%M:%S",localtime(process_time))))
